<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <link rel="shortcut icon" href="/favicon.ico"/>
    <link rel="bookmark" href="/favicon.ico"/>
    <meta charset="UTF-8"/>
    <title>待审核任务列表</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link rel="stylesheet" th:href="@{/layuiadmin/layui/css/layui.css}"  media="all">
    <link rel="stylesheet" th:href="@{/layuiadmin/style/admin.css}" media="all">
</head>
<body>
<div class="layui-fluid">
    <div class="layui-row layui-col-space15">
        <div class="layui-col-md12">
            <div class="layui-card">
                <div class="layui-card-header">待审核任务列表</div>
                <div class="layui-card-body">

                    <table class="layui-hide" id="test-table-reload" lay-filter="test-table-reload"></table>

                    <script type="text/html" id="barlist">
                        <a class="layui-btn layui-btn-xs" lay-event="agree">同意</a>
                        <a class="layui-btn layui-btn-xs" lay-event="reject">拒绝</a>
                    </script>
                </div>
            </div>
        </div>
    </div>
</div>

<script th:src="@{/layuimini/js/layui.js}"></script>
<script type="text/javascript">
    function createTime(v){
        var date = new Date(v);
        var y = date.getFullYear();
        var m = date.getMonth()+1;
        m = m<10?'0'+m:m;
        var d = date.getDate();
        d = d<10?("0"+d):d;
        var h = date.getHours();
        h = h<10?("0"+h):h;
        var M = date.getMinutes();
        M = M<10?("0"+M):M;
        var str = y+"-"+m+"-"+d+" "+h+":"+M;
        return str;
    }
</script>
<script>
    /* 时间戳转化开始 */
    Date.prototype.format = function (fmt) { //author: meizz
        var o = {
            "M+": this.getMonth() + 1,//月份
            "d+": this.getDate(),//日
            "h+": this.getHours(),//小时
            "m+": this.getMinutes(),//分
            "s+": this.getSeconds(),//秒
            "q+": Math.floor((this.getMonth() + 3) / 3),//q是季度
            "S": this.getMilliseconds() //毫秒
        };
        if (/(y+)/.test(fmt)) fmt = fmt.replace(RegExp.$1,(this.getFullYear() + "").substr(4 - RegExp.$1.length));
        for (var k in o)
            if (new RegExp("(" + k + ")").test(fmt)) fmt = fmt.replace(RegExp.$1,(RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
        return fmt;
    }

    String.prototype.format = function (args) {
        var result = this;
        if (arguments.length > 0) {
            if (arguments.length == 1 && typeof (args) == "loginTime") {
                for (var key in args) {
                    if (args[key] != undefined) {
                        var reg = new RegExp("({" + key + "})","g");
                        result = result.replace(reg,args[key]);
                    }
                }
            }
            else {
                for (var i = 0; i < arguments.length; i++) {
                    if (arguments[i] != undefined) {
                        //var reg = new RegExp("({[" + i + "]})","g");//这个在索引大于9时会有问题
                        var reg = new RegExp("({)" + i + "(})",arguments[i]);
                    }
                }
            }
        }
        return result;
    }
    function dateFormat(value) {
        return value ? new Date(value*1000).format("yyyy-MM-dd hh:mm:ss") : "";
    }
</script>
<script type="text/html">
    <a id="timedemo">{{createTime(d.paytime)}}</a>
</script>
<script>
    layui.use('table', function(){
        var table = layui.table;

        //方法级渲染
        table.render({
            elem: '#test-table-reload'
            ,url: 'http://localhost:8080/checkingTask/findAllCheckingTask'
            ,headers: {'X-Authorization-With':window.sessionStorage.getItem('jwt')}
            ,cols: [
                [
                    {checkbox: true, fixed: true}
                    ,{field:'id', title: '待审核任务号', width:176, sort: true, align:'center'}
                    ,{field:'orderId', title: '订单号', width:176,  align:'center'}
                    ,{field:'userId', title: '用户Id', width:176, align:'center'}
                    ,{field:'createTime', title: '申请时间', width:176, align:'center',templet:'<div>{{createTime(d.createTime)}}</div>'}
                    ,{field:'modifyTime', title: '修改时间', width:176,sort: true, align:'center',templet:'<div>{{createTime(d.modifyTime)}}</div>'}
                    ,{field:'businessDesc', title: '业务描述',width:150, align:'center'}
                    ,{width:150, title:'操作', align:'center', toolbar: '#barlist'}
                ]
            ]
            ,page: true
            , parseData: function (res) { //将原始数据解析成 table 组件所规定的数据
                return {
                    "code": res.code, //解析接口状态
                    "msg": res.msg, //解析提示文本
                    "count": res.data.total, //解析数据长度
                    "data": res.data.rows //解析数据列表
                };
            }
            ,height: 470
        });

        //监听工具条
        table.on('tool(test-table-reload)', function(obj){
            //var data = JSON.stringify({id:obj.id});
            var data = obj.data;
            var parms = JSON.stringify(data);
            if(obj.event === 'agree'){
                layer.confirm('确定同意吗？', function(index){
                    layer.close(index);
                    $.ajax({
                        type: "POST",
                        url: "/checkingTask/agree" ,
                        data: parms,
                        dataType: "json",
                        contentType: "application/json;charset=utf-8",
                        success: function(result) {
                            if(result.code == 200) {
                                layer.msg(result.msg,{icon: 1});
                            } else {
                                layer.msg(result.msg, {
                                    icon: 5
                                });
                            }
                        }
                    });
                });
            } else if(obj.event === 'reject') {
                    layer.confirm('确定拒绝吗？', function(index){
                        layer.close(index);
                        $.ajax({
                            type: "POST",
                            url: "/checkingTask/reject" ,
                            data: parms,
                            dataType: "json",
                            contentType: "application/json;charset=utf-8",
                            success: function(result) {
                                if(result.code == 200) {
                                    layer.msg(result.msg,{icon: 1});
                                } else {
                                    layer.msg(result.msg, {
                                        icon: 5
                                    });
                                }
                            }
                        });
                    });
                }
        });

        var $ = layui.$, active = {
            reload: function(){
                var demoReload = $('#test-table-demoReload');

                //执行重载
                table.reload('test-table-reload', {
                    page: {
                        curr: 1 //重新从第 1 页开始
                    }
                    ,where: {
                        key: {
                            id: demoReload.val()
                        }
                    }
                });
            }
        };

        $('.test-table-reload-btn .layui-btn').on('click', function(){
            var type = $(this).data('type');
            active[type] ? active[type].call(this) : '';
        });

    });
</script>


</body>
</html>